import $http  from "@/utils/http";
import $toast from '@/utils/toast';

/**
 * 添加购物车
 * @param {[type]} options.uid        用户ID
 * @param {[type]} options.sku_id     skuid
 * @param {[type]} options.goods_type 类型 1 在售 2预购
 * @param {[type]} options.quantity   数量
 * @param Promise
 */
export function addCart({ uid, sku_id, goods_type, quantity })
{

	if(!sku_id)
		return new Promise ( () =>{ $toast('SKU_ID 不能为空') });

	if(!goods_type)
		return new Promise ( () =>{ $toast('GOODS_TYPE 不能为空') });

	if(!quantity)
		return new Promise ( () =>{ $toast('QUANTITY 不能为空') });

	return $http.post('',{ module : "Cartinfo#addCart", uid, sku_id, goods_type, quantity }) 
}

/**
 * 立即支付订单详情
 * @param  {[type]} options.uid              用户ID
 * @param  {[type]} options.goods_sku_string 规格id
 * @param  {[type]} options.coupon_ids       优惠券
 * @return Promise
 */
export function getOrderDetail({ uid, goods_sku_string, coupon_ids, fuid })
{

	return $http.post('',{ module : "Paymentorder#onPayOrderDetail", uid, goods_sku_string, coupon_ids, fuid }) 
}


/**
 * 优惠券列表
 * @param  {[type]} uid      用户ID
 * @param  {[type]} shop_id  店铺id
 * @param  {[type]} goods_id 商品id
 * @return Promise
 */
export function getCouponList( uid, shop_id, goods_id )
{

	return $http.post('',{ module : "Couponinfo#getCouponList", uid, shop_id,goods_id}) 
}

/**
 * 领取优惠券
 * @param  {[type]} options.uid            用户ID
 * @param  {[type]} options.shop_id        商品id
 * @param  {[type]} options.coupon_type_id 券id
 * @return Promise
 */
export function receiveCoupon({ uid, shop_id, coupon_type_id })
{

	return $http.post('',{ module : "Couponinfo#receiveCoupon", uid, shop_id, coupon_type_id }) 
}




/**
 * 支付订单优惠券列表
 * @param  {[type]} options.uid        用户ID
 * @param  {[type]} options.shop_ids   店铺ids 请以,分隔
 * @param  {[type]} options.goods_ids  商品id组 请以,分隔
 * @param  {[type]} options.coupon_ids 优惠券ids 请以,分隔
 * @return Promise
 */
export function getUseCouponList({ uid, shop_ids, goods_ids, coupon_ids })
{

	return $http.post('',{ module : "Couponinfo#useCouponList", uid, shop_ids, goods_ids, coupon_ids }) 
}


/**
 * 惊喜券列表
 * @param  {[type]} uid       用户ID
 * @param  {[type]} goods_ids 商品ID 请以,隔开
 * @return Promise
 */
export function getSurpriseList(uid, goods_ids)
{

	return $http.post('',{ module : 'Couponinfo#userSurpriseUseList', uid, goods_ids });
}


/**
 * 关注商品或者店铺
 * @param {[type]} fav_id   商品ID
 * @param {[type]} fav_type 类型:goods为商品,shop为店铺,默认为商品
 * @param {[type]} uid      会员ID
 * @param Promise
 */
export function addAttention({ fav_id ,fav_type, uid })
{
	switch(true) 
	{
		case !fav_id:
			return new Promise(() => { $toast(' FAV_ID 不能为空') });

		case !fav_type:
			return new Promise(() => { $toast(' FAV_TYPE 不能为空') });
	}
	
	return $http.post('',{ module : 'Shop#collectionGoodsOrShop', fav_id, fav_type, uid });
}

/**
 * 取消关注商品或者店铺
 * @param {[type]} fav_id   商品ID
 * @param {[type]} fav_type 类型:goods为商品,shop为店铺,默认为商品
 * @param {[type]} uid      会员ID
 * @param Promise
 */
export function delAttention({ fav_id ,fav_type, uid })
{
	switch(true) 
	{
		case !fav_id:
			return new Promise(() => { $toast(' FAV_ID 不能为空') });

		case !fav_type:
			return new Promise(() => { $toast(' FAV_TYPE 不能为空') });
	}
	
	return $http.post('',{ module : 'Shop#cancelCollGoodsOrShop', fav_id, fav_type, uid });
}


/**
 * 判断是否关注
 * @param {[type]} fav_id   商品ID
 * @param {[type]} fav_type 类型:goods为商品,shop为店铺,默认为商品
 * @param {[type]} uid      会员ID
 * @param Promise
 */
export function isAttention({ fav_id ,fav_type, uid })
{
	switch(true) 
	{
		case !fav_id:
			return new Promise(() => { $toast(' FAV_ID 不能为空') });

		case !fav_type:
			return new Promise(() => { $toast(' FAV_TYPE 不能为空') });
	}
	
	return $http.post('',{ module : 'Shop#isCollection', fav_id, fav_type, uid });
}


/**
 * 购物车列表
 * @param  {[type]} uid  用户ID
 * @param  {[type]} type 1 在售 2预购
 * @return Promise
 */
export function getCartList( uid, type )
{
	if(!type)
		return new Promise ( ()=> { $toast('TYPE 不能为空') });

	return $http.post('',{ module : 'Cartinfo#cartList', uid, type });
}

/**
 * 购物车删除商品
 * @param  {[type]} options.uid        用户ID
 * @param  {[type]} options.sku_id     规格id
 * @param  {[type]} options.goods_type 类型 1 在售 2预购
 * @return Promise
 */
export function removeCart({ uid, sku_id, goods_type })
{
	return $http.post('',{ module : 'Cartinfo#delCart', uid, sku_id, goods_type });
}

/**
 * 购物车增减数量
 * @param  {[type]} options.uid        用户ID
 * @param  {[type]} options.sku_id     规格id
 * @param  {[type]} options.goods_type 类型 1 在售 2预购
 * @param  {[type]} options.quantity   数量
 * @return Promise
 */
export function changeNum({ uid, sku_id, goods_type, quantity })
{
	
	return $http.post('',{ module : 'Cartinfo#incOrdincMoneyChange',uid, sku_id, goods_type, quantity });
}


/**
 * 创建订单
 * @param  {[type]} options.uid                  用户ID
 * @param  {[type]} options.goods_sku_list       规格+数量
 * @param  {[type]} options.surprise_id          惊喜券ID
 * @param  {[type]} options.coupon_ids           优惠券id    999,1000
 * @param  {[type]} options.shipping_company_ids 物流公司    id 0:0,80:8
 * @param  {[type]} options.goods_type           商品类型
 * @param  {[type]} options.payment_type         支付类型 1：App微信支付 2：支付宝
 * @param  {[type]} options.pay_cate             付款模式 1定金 0全款 2尾款
 * @param  {[type]} options.address_id           用户地址id
 * @return Promise
 */
export function createOrder(
{	
	uid, 
	goods_sku_list,
	surprise_id, 
	coupon_ids,
	shipping_company_ids, 
	goods_type, 
	payment_type, 
	pay_cate, 
	address_id,
	fuid,
	goods_id,
	is_ping,
	words          
} = {})
{
	return $http.post('',{ module : 'Paymentorder#createOrder',
		uid, 
		goods_sku_list, 
		surprise_id, 
		coupon_ids, 
		shipping_company_ids, 
		goods_type, 
		payment_type, 
		pay_cate, 
		address_id,
		fuid,
		goods_id,
		is_ping,
		words
	})
}

/**
 * 立即付款
 * @param  {[type]} options.uid        用户ID
 * @param  {[type]} options.order_id   订单id
 * @param  {[type]} options.order_type 订单类型 0:在售订单；2:预购订单
 * @param  {[type]} options.pay_mode   预购付款模式 1定金，2尾款 0全款
 * @param  {[type]} options.type       1微信 2支付宝
 * @return Promise
 */
export function payOrder({ uid, order_id, order_type, pay_mode, type,identify_id })
{
	return $http.post('', { module : 'Paymentorder#payrest', uid, order_id, order_type, pay_mode, type,identify_id })
}


/**
 * 付款模式
 * @param  {[type]} goods_sku_ids 规格id
 * @return Promise
 */
export function getPayMode( goods_sku_ids )
{
	return $http.post('', { module : 'Paymentorder#payMode',goods_sku_ids })
}

